package com.tree.zk.autoconfig;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * package com.tree.zk.autoconfig
 * description:
 *
 * @author tree
 * @date 2019-08-22 10:21
 */
@Configuration
@EnableConfigurationProperties(ZookeeperProperties.class)
@ConditionalOnProperty(
        value = {"zookeeper.enabled"},
        matchIfMissing = false
)
public class ZookeeperAutoConfiguration {

    @Bean(initMethod = "init", destroyMethod = "destroy")
    public ZkClient zkClient(ZookeeperProperties zookeeperProperties) {
        ZkClient zkClient = new ZkClient(zookeeperProperties);
        return zkClient;
    }

    /**
//     * 用于分布于测试，正式使用请删除
//     * @return
//     */
//    @Bean(initMethod = "init", destroyMethod = "stop")
//    public ZkClient zkClientTest() {
//        ZkClient zkClient = new ZkClient(zookeeperProperties);
//        return zkClient;
//    }


}
